package service;

import pub.ConfigFile;
import android.content.Context;
import file.ConfigProperties;

public class ReadAndSaveConfig {
	private Context context;

	public ReadAndSaveConfig(Context context){
		this.context=context;
	}
	
	public void readAll () {
		readFtp();
    	readCurrConfig();
    	readUserConfig();
    	readVersionConfig();
	}
	
	public void readFtp () {
		ConfigProperties cp=new ConfigProperties("ftp.properties");
		ConfigFile.ftpServer=cp.getNetConfigProperties(context, "ftpServerIp","199.192.154.98");//"ftp.byethost22.com");
		ConfigFile.ftpUser=cp.getNetConfigProperties(context, "ftpUser","ftpUser");
		ConfigFile.ftpPassword=cp.getNetConfigProperties(context, "ftpPassword","Ftp123456");
		
		//ConfigFile.ftpServer=cp.getNetConfigProperties(context, "ftpServerIp","172.17.1.244");//"ftp.byethost22.com");
		//ConfigFile.ftpUser=cp.getNetConfigProperties(context, "ftpUser","jbh");
		//ConfigFile.ftpPassword=cp.getNetConfigProperties(context, "ftpPassword","jbh");
		
	}
	public void readCurrConfig () {
		ConfigProperties cp=new ConfigProperties("config.properties");
		ConfigFile.APP_NAME=cp.getNetConfigProperties(context, "APP_NAME","HACKER");
		ConfigFile.APP_NAME="0";
		ConfigFile.SERVER_IP=cp.getNetConfigProperties(context, "SERVER_IP","218.203.51.194");
		//ConfigFile.SERVER_IP="192.168.100.102";
		ConfigFile.SERVER_PORT=cp.getNetConfigProperties(context, "SERVER_PORT",5188);
		ConfigFile.UDP_MAX_LEN=cp.getNetConfigProperties(context, "UDP_MAX_LEN",512);
		ConfigFile.HEART_TIME=cp.getNetConfigProperties(context, "HEART_TIME",3000);
		//ConfigFile.APK_VERSION=cp.getNetConfigProperties(context, "APK_VERSION","1.0.0");
	}
	
	public void readUserConfig () {
		ConfigProperties cp=new ConfigProperties("user.properties");
		ConfigFile.CurrSendUser=cp.getNetConfigProperties(context, "CurrSendUser",ConfigFile.CurrSendUser);
		ConfigFile.AllSendUser=cp.getNetConfigProperties(context, "AllSendUser",ConfigFile.AllSendUser);//"ftp.byethost22.com");
		ConfigFile.MyLocation.dJd=cp.getNetConfigProperties(context, "defultJd",23.149684);
		ConfigFile.MyLocation.dWd=cp.getNetConfigProperties(context, "defultWd",114.417107);
		ConfigFile.RecordPath=cp.getNetConfigProperties(context, "RecordPath","");
		ConfigFile.RecordSwitch=cp.getNetConfigProperties(context, "RecordSwitch",1);
	}
	
	public void SaveUserConfig () {
		ConfigProperties cp=new ConfigProperties("user.properties");
		cp.setNetConfigProperties(context, "CurrSendUser",ConfigFile.CurrSendUser);
		cp.setNetConfigProperties(context, "AllSendUser",ConfigFile.AllSendUser);//"ftp.byethost22.com");	
	}
	
	public void readVersionConfig () {
		ConfigProperties cp=new ConfigProperties("user.properties");
		ConfigFile.UPDATE_VERSION=cp.getNetConfigProperties(context, "AppVersion",ConfigFile.APK_VERSION);
		ConfigFile.DOWNLOAD_VERSION=cp.getNetConfigProperties(context, "NewFtpVersion",ConfigFile.APK_VERSION);
	}
	
	public void SaveVersionConfig (String ver) {
		ConfigProperties cp=new ConfigProperties("user.properties");
		cp.setNetConfigProperties(context, "AppVersion",ver);
	}
	
	public void SaveNewFtpVersion (String ver) {
		ConfigProperties cp=new ConfigProperties("user.properties");
		cp.setNetConfigProperties(context, "NewFtpVersion",ver);
	}
	}
